/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
public:
    bool chkPalindrome(ListNode* A) {
        if(!A || !(A->next))
            return true;
        struct ListNode* slow = A;
        struct ListNode* fast = A;
        struct ListNode* prev = nullptr;
        while(fast && (fast->next)){
            prev = slow;
            fast = fast->next->next;
            slow = slow->next;
        }
        //遍历退出后，slow为中间节点
        prev->next = NULL;
        //将第二个链表进行逆置
        struct ListNode* cur = slow;
        struct ListNode* next = slow;
        struct ListNode* temp = nullptr;
        while(cur){
            next = cur->next;
            cur->next = temp;
            temp = cur;
            cur = next;
        }
        //退出循环后，temp为逆置后的链表首节点     
        struct ListNode* cur2 = temp;
        struct ListNode* cur1 = A;
        
        while(cur1){
            if(cur1->val != cur2->val)
                return false;
            cur1 = cur1->next;
            cur2 = cur2->next;     
        }
        return true;
        
    }
};